<template>
  <div>
    <Header></Header>
    <Swiper :swiper="swiperList"></Swiper>
  </div>
</template>

<script>
import Swiper from '../swiper'
import Header from './header'
import api from '@/config/api'
import { sendPost } from '@/utils/http'
export default {
  data () {
    return {
      swiperList: [],
      position:''
    }
  },
  components: {
    Swiper,
    Header
  },
  created () {
    if (!sessionStorage.getItem('activeIndex')) {
      sessionStorage.setItem('activeIndex', 'courses')
    }
    this.getBannerList(this.position)
  },
  watch: {
    $route (to, from) {

      switch (to.path) {
        case '/courses':
          this.position='1'
          this.getBannerList(this.position)
          sessionStorage.setItem('pos',this.position)
          // sendPost(api.getBannerList, { position: '1' }).then(res => {
          //   // console.log(res.data, '1');
          //   this.swiperList = res.data
          // })
          break;

        case '/community':
          this.position='3'
          this.getBannerList(this.position)
           sessionStorage.setItem('pos',this.position)
          // sendPost(api.getBannerList, { position: '3' }).then(res => {
          //   // console.log(res.data, '1');
          //   this.swiperList = res.data
          // })
          break;

        case '/loged' :
          this.position='2'
          this.getBannerList(this.position)
           sessionStorage.setItem('pos',this.position)
          // sendPost(api.getBannerList, { position: '2' }).then(res => {
          //   // console.log(res.data, '1');
          //   this.swiperList = res.data
          // })
          break;

        case '/practice' :
          this.position='2'
          this.getBannerList(this.position)
           sessionStorage.setItem('pos',this.position)
          // sendPost(api.getBannerList, { position: '2' }).then(res => {
          //   // console.log(res.data, '1');
          //   this.swiperList = res.data
          // })
          break;

        case '/userinfo':
          this.position='3'
          // sendPost(api.getBannerList, { position: '4' }).then(res => {
          //   // console.log(res.data, '1');
          //   this.swiperList = res.data
          // })
          this.getBannerList(this.position)
           sessionStorage.setItem('pos',this.position)
          break;
      }
    }
  },
  methods: {
    // 获取轮播图数据
    getBannerList (position) {
      console.log(position);
      if(!position){
        position=sessionStorage.getItem('pos')
      }
      sendPost(api.getBannerList, { position: position }).then(res => {
        this.swiperList = res.data
      })

    }
  }
}
</script>

<style lang="less">
.el-menu--horizontal > .el-menu-item {
  border-top: 0.125rem solid transparent;
  color: #333333;
  box-sizing: border-box;
  border-bottom: 0px solid #000;
}
.el-menu--horizontal > .el-menu-item.is-active {
  border-bottom: 0;
  border-top: 0.125rem solid rgb(255, 83, 66);
  box-sizing: border-box;
}
.el-menu {
  color: #333333;
}
.el-menu-item.is-active {
  background-color: transparent !important;
}
.el-menu-item {
  background-color: rgba(0, 0, 0, 0) !important;
  font-size: 1.125rem;
}
.el-menu.el-menu--horizontal {
  border-bottom: none;
}
.icon-lingdang1 {
  color: #eee;
  line-height: 3.75rem;
}
.avatar {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  display: inline-block;
  vertical-align: middle;
}
.username {
  display: inline-block;
  margin-left: 0.625rem;
  font-weight: bold;
  font-size: 1rem;
  color: #333333;
  width: 6.25rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>
